﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Chinaer.WCF.Services;

namespace Chinaer.UI.MVC.Controllers
{
    public class ProvinceController : Controller
    {
        //
        // GET: /Province/

        public ActionResult Index()
        {
            return View();
        }

        public ContentResult GetProvinceByCountryID(string ID)
        {
            ChinaerService chinaerService = new ChinaerService();
            List<DTO.ProvinceDTO> listProvince = chinaerService.GetProvinceByCountryID(ID, "");
            string jsonResult = Helper.JsonHelper.GetJson(listProvince, listProvince.Count);
            //return new JsonResult()
            //{
            //    Data = jsonResult,
            //    JsonRequestBehavior = JsonRequestBehavior.AllowGet
            //};
            return new ContentResult()
            {
                Content = jsonResult
            };
        }
        public ContentResult GetAllProvinceByCountryID(string ID)
        {
            ChinaerService chinaerService = new ChinaerService();
            List<DTO.ProvinceDTO> listProvince = chinaerService.GetProvinceByCountryID(ID, "");
            string jsonResult = Helper.JsonHelper.CreateJson(listProvince);
            //return new JsonResult()
            //{
            //    Data = jsonResult,
            //    JsonRequestBehavior = JsonRequestBehavior.AllowGet
            //};
            return new ContentResult()
            {
                Content = jsonResult
            };
        }
        [HttpPost]
        public string SaveProvince(DTO.ProvinceDTO provinceDTO)
        {
            ChinaerService chinaService = new ChinaerService();
            Model.Common.JsonResult jsonResult = chinaService.AddProvince(provinceDTO);
            return Helper.JsonHelper.CreateJson(jsonResult);
        }
        [HttpPost]
        public string UpdateProvince(DTO.ProvinceDTO provinceDTO)
        {
            ChinaerService chinaService = new ChinaerService();
            Model.Common.JsonResult jsonResult = chinaService.UpdateProvince(provinceDTO);
            return Helper.JsonHelper.CreateJson(jsonResult);
        }
        [HttpPost]
        public string DeleteProvince(string ID)
        {
            ChinaerService chinaService = new ChinaerService();
            Model.Common.JsonResult jsonResult = chinaService.DeleteProvinceByID(ID, "");
            return Helper.JsonHelper.CreateJson(jsonResult);
        }
    }
}
